package cn.zyx.order.service.impl;

import cn.zyx.basic.service.impl.BaseServiceImpl;
import cn.zyx.basic.util.PageList;
import cn.zyx.order.domain.PetAcquisitionOrder;
import cn.zyx.order.domain.ProductOrder;
import cn.zyx.order.query.PetAcquisitionOrderQuery;
import cn.zyx.order.service.IPetAcquisitionOrderService;
import cn.zyx.org.domain.Employee;
import cn.zyx.org.mapper.EmployeeMapper;
import cn.zyx.user.domain.User;
import cn.zyx.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PetAcquistionOrderServiceImpl extends BaseServiceImpl<PetAcquisitionOrder> implements IPetAcquisitionOrderService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private UserMapper userMapper;


    @Override
    public PageList<PetAcquisitionOrder> queryAdmin(PetAcquisitionOrderQuery query, Long loginInfoId) {
        //1.通过loginInfoID查询出Employee
        Employee employee = employeeMapper.loadByLoginInfoId(loginInfoId);
        //2.如果employee中的shopID不为null,就是店铺。否则就是平台员工
        if (employee.getShop_id() != null) {
            query.setShopId(employee.getShop_id());
        }
        return super.queryPage(query);
    }

    @Override
    public PageList<PetAcquisitionOrder> queryUser(PetAcquisitionOrderQuery query, Long loginInfoId) {
        // 查询当前用户信息
        User user = userMapper.loadByLoginInfoId(loginInfoId);
        // 给用户字段赋值
        query.setUserId(user.getId());
        return super.queryPage(query);
    }
}
